angular.module('starter.controllers', [])
  .controller('AllCtrl', function($scope,$ionicHistory) {
    //这个方法是用来返回上一页的
    $scope.gotoback=function () {
      $ionicHistory.goBack();
    }
    $scope.gotoDetail=function (id) {
      location.href="#/activeDetail";
    }
  })
.controller('DashCtrl', function($scope,$http,$ionicLoading) {
  $ionicLoading.show({
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  });
  $http({
    method :'GET',
    url : '../www/json/active.json'
  }).success(function(data) {
    $ionicLoading.hide();
    $scope.activeInfor=data;
    console.log($scope.activeInfor);
  }).error(function(response){
    alert("数据获取失败");
  });
})
.controller('ChatsCtrl', function($scope,$http,$ionicLoading) {
  $ionicLoading.show({
    content: 'Loading',
    animation: 'fade-in',
    showBackdrop: true,
    maxWidth: 200,
    showDelay: 0
  });
  $http({
    method :'GET',
    url : '../www/json/active.json'
  }).success(function(data) {
    $ionicLoading.hide();
    $scope.activeInfor=data;
    console.log($scope.activeInfor);
  }).error(function(response){
    alert("数据获取失败");
  });

})
.controller('AccountCtrl', function($scope) {

})
  .controller('LoginCtrl',function ($scope,$http,$ionicLoading) {
    $scope.login = function () {
      $ionicLoading.show({
        content: 'Loading',
        animation: 'fade-in',
        showBackdrop: true,
        maxWidth: 200,
        showDelay: 0
      });
      $http({
        method :'POST',
        url : IP+'/loginCheck.php',
        data:{
          user:$scope.userName,
          password:$scope.passWord
        }
      }).success(function(data) {
        $ionicLoading.hide();
           console.log(data);
      }).error(function(response){
        $ionicLoading.hide();
        alert("登陆失败");
      });
    }
  })
  .controller('RegistCtrl',function ($scope,$http) {
    $scope.regist = function () {
      if($scope.surePass==$scope.userPass){
        $http({
          method :'POST',
          url : IP+'/loginChek.php',
          data:{
            user:$scope.userName,
            password:$scope.passWord,
            userage:$scope.userAge,
            usermail:$scope.userMail
          }
        }).success(function(data) {
          console.log(data);
        }).error(function(response){
          alert("注册失败");
        });
      }else{
        alert("两次密码不一致");
      }
    }
  })
;
